﻿using AutoMapper;
using MediatR;
using S.Organization.API.Application.Command.SheepFarmCommand;
using S.Organization.API.Application.Command.SupplierCommand;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;

namespace S.Organization.API.Application.CommandHandler.SupplierCommandHandler
{
    public class DelSupplierCommandHandler : IRequestHandler<DelSupplierCommand, int>
    {
        private readonly IBaseRepository<Supplier> _repository;
        private readonly IMapper mapper;

        public DelSupplierCommandHandler(IBaseRepository<Supplier> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(DelSupplierCommand request, CancellationToken cancellationToken)
        {

            var list = await _repository.GetAllAsync();
            list = list.Where(x => x.SupplierId == request.SupplierId).ToList();
            return await _repository.DeleteAsync(list);

        }
    }
}
